home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / music_utilities / pt013.dms / pt013.adf / Programmers / MODPlayer / modplayer.doc < prev    next >
Text File  |  1991-08-25  |  8KB  |  237 lines

  1.      Instructions for using "modplayer.a", the stand-alone playroutine.
  2.  
  3. "modplayer" is a piece of code (about 3 - 5 KBytes, depending on your needs)
  4. which is linked with your program and plays modules made in MED.
  5.  
  6. "modplayer" contains the following routines:
  7.     InitPlayer
  8.     RemPlayer
  9.     PlayModule
  10.     ContModule
  11.     StopPlayer
  12.     SetTempo
  13.  
  14. The arguments are passed in registers, and return values are returned in d0.
  15. These routines will trash registers d0-d1 and a0-a1.
  16.  
  17. And now the descriptions of each one:
  18. --------------------------------------------------------------------------
  19. InitPlayer -- initialize everything
  20.  
  21. Before you can call the other functions, you must call this function.
  22. It allocates the audio channels, timer, serial port (if MIDI) etc...
  23.  
  24. ARGUMENTS:    none
  25.  
  26. RETURNS:    0 if everything is ok, otherwise something failed.
  27.         If something failed, you can still call the other
  28.         routines - they just don't do anything.
  29. --------------------------------------------------------------------------
  30. RemPlayer -- return everything back
  31.  
  32. Call this when your program exits. It frees the audio channels etc. etc.
  33.  
  34. ARGUMENTS:    none
  35.  
  36. RETURNS:    nothing
  37. --------------------------------------------------------------------------
  38. PlayModule -- start playing a module
  39.  
  40. When you want to start playing call this.
  41.  
  42. ARGUMENTS:    a0 = pointer to the module. Where to get that pointer?
  43.         Don't panic, it's explained later....
  44.  
  45. RETURNS:    nothing
  46. --------------------------------------------------------------------------
  47. StopPlayer -- stop playing
  48.  
  49. ARGUMENTS:    no arguments
  50.  
  51. RETURNS:    nothing
  52. --------------------------------------------------------------------------
  53. ContModule -- continue playing
  54.  
  55. This routine continues playing the module from the point it was stopped.
  56.  
  57. ARGUMENTS:    a0 = pointer to the module
  58.  
  59. RETURNS:    nothing
  60. --------------------------------------------------------------------------
  61. SetTempo -- set the playback tempo
  62.  
  63. ARGUMENTS:    d0 = new tempo (1 - 240)
  64.  
  65. RETURNS:    nothing
  66. --------------------------------------------------------------------------
  67.  
  68. "modplayer.a" is the source code of the music routine. It contains stuff
  69. that may be unnecessary for your purposes, that just takes time and memory.
  70. There are some "switches" at the beginning of the source, that allow you
  71. to turn off features you don't need. They are:
  72.  
  73. MIDI        If the song(s) use(s) only the Amiga audio channels, set
  74.         this to 0.
  75. AUDDEV        For some purposes, you may want to disable the code that
  76.         allocates the audio channels using "audio.device", e.g.
  77.         in a non-multitasking environment. Normally this should
  78.         be 1.
  79. SYNTH        If the song(s) doesn't use synth/hybrid sounds, then this
  80.         can be set to zero.
  81. CHECK        This does some checkings to ensure that several values are
  82.         correct (e.g. is the sample in memory, no Amiga effects on
  83.         MIDI-tracks etc..). If you know that the song is correct,
  84.         you can safely turn the checks off.
  85. RELVOL        If you don't need the "relative volume", this can be zero.
  86. IFF53        If the song doesn't contain IFF 3- or 5-octave samples,
  87.         this can be zero.
  88. HOLD        This turns off the hold/decay features.
  89.  
  90.  
  91. There's an additional flag, EASY. If set, the usage of the player routines
  92. is even more simplified, and you enter the module name into an INCBIN
  93. statement. Then there are two routines (_startmusic, _endmusic) you call
  94. to start and stop the music (the music can be started ONLY ONCE). The
  95. EASY option is suitable for demos etc. where only a single tune is
  96. required. This option also replaces the 'easyplayer.a' from the previous
  97. release of OctaMED and MED.
  98.  
  99. "modplayer.a" also supports multi-modules. It defines a UWORD modnum
  100. (in assembler: _modnum). Set this variable to the number of the song
  101. you want to play before calling PlayModule (0 is the first, 1 is the
  102. second song etc..). For example:
  103.     #include "modplayer.h" /* defines 'modnum' */
  104.     ...
  105.     modnum = 1; /* Play the second module */
  106.     PlayModule(module);
  107.     ...
  108. Assembler:
  109.     xref    _modnum
  110.     xref    _PlayModule
  111.     ...
  112.     move.w    #1,_modnum
  113.     lea    _module,a0
  114.     jsr    _PlayModule(pc)
  115.     ...
  116.  
  117. Timing
  118. ======
  119. If you need vertical blanking timing, you can set VBLANK to 1 and CIAB to 0.
  120. In normal use this is not recommended (because of the 16 % difference in
  121. playing speed with NTSC and PAL Amigas).
  122.  
  123. Assembling
  124. ==========
  125. "modplayer.a" can be assembled by using A68k V2.61 (or later) or HiSoft
  126. Devpac 2 without need to make changes. Other assemblers may need some
  127. small changes to work correctly (mostly because the directives they support
  128. may be slightly different). The freely distributable assembler, A68k is
  129. available e.g. on Fish disk #314. If you've working on a linker environment
  130. (e.g. programming in C), you've to include the resulted "modplayer.o" in
  131. your .lnk-file.
  132.  
  133. ==========================================================================
  134.  
  135. And how to get some music?
  136.  
  137. You have two ways to get the music:
  138. 1. Include the module in your final executable.
  139. 2. Save the module as a separate disk file and load it when needed
  140.    (this is probably the best way if you have more than one song, and
  141.     you don't want to use multi-modules).
  142.  
  143. First I cover the first method:
  144. --------------------------------------------------------------------------
  145. Including the module in your final executable:
  146.  
  147. The direct object file saving is removed now (you can still use the previous
  148. versions which support it, if you want). There's now another way to convert
  149. the song to an object file.
  150.  
  151. There's a new utility, Objconv, which loads the module and dumps it into an
  152. object file. Here's an example how to use it:
  153.  
  154. - Save the song as a module (MED module!).
  155. - Use Objconv e.g. objconv medmodule mod.o
  156. - Objconv requests the symbol name, enter "song" (without "'s), for example.
  157. - Now there's a file 'mod.o'. Link this file, and the file 'reloc.o'
  158.   with your program.
  159. - In your program, you define the module:
  160.     #include "modplayer.h"
  161.     ...
  162.     extern struct MMD0 far song;
  163.   You must relocate the module before it's used. Do this only once!
  164.   This is done by
  165.     RelocModule(&song);
  166.   RelocModule expects the argument in stack, so use __stdargs, if you've
  167.   turned registerized arguments on.
  168.  
  169. In assembler, you'd do exactly in the same way, except:
  170.     xref    _song
  171.     xref    _RelocModule
  172.     xref    _PlayModule
  173.  
  174.     ... (assuming all init stuff is here)
  175.  
  176.     lea    _song,a0
  177.     move.l    a0,-(sp)    ;push in stack
  178.     jsr    _RelocModule(pc)
  179.     lea    _song,a0    ;this is passed in register a0
  180.     jsr    _PlayModule
  181.     ...
  182.  
  183. Note: if you've got an assembler that supports 'incbin' directive or
  184. equivalent, you can use it instead of the Objconv. Relocation is required
  185. in any case.
  186.  
  187. And the second method (loading modules from disk):
  188. --------------------------------------------------------------------------
  189. File "loadmod.a" contains three routines:
  190.     LoadModule
  191.     UnLoadModule
  192.     RelocModule (not external)
  193.  
  194. You usually need only the first two of them. RelocModule is used by
  195. LoadModule.
  196.  
  197. --------------------------------------------------------------------------
  198. LoadModule -- loads a module from disk
  199.  
  200. This function loads a module from disk. Note that relocation is done
  201. automatically, so you must not RelocModule() a module obtained by using
  202. this routine.
  203.  
  204. ARGUMENTS:    a0 = pointer to file name
  205.  
  206. RETURNS:    d0 = pointer to the module, if something failed: 0
  207. --------------------------------------------------------------------------
  208. UnLoadModule -- free the module from memory
  209.  
  210. Frees the module. Remember to StopPlayer() before you unload the module
  211. that is currently playing. Also remember to free all modules you've loaded
  212. before you exit the program.
  213.  
  214. ARGUMENTS:    a0 = pointer to the module (may be 0)
  215.  
  216. RETURNS:    nothing, nothing and nothing
  217. --------------------------------------------------------------------------
  218.  
  219. Just call LoadModule to load the module and send the returned pointer to
  220. PlayModule. Easy??
  221.  
  222. ==========================================================================
  223.  
  224. REMEMBER:    All functions expect the arguments in registers (except
  225.         RelocModule() from reloc.o). This is automatically (??)
  226.         handled by you when you program in assembler, but it is
  227.         not automatically handled when you're programming in C.
  228.  
  229. If you have Lattice/SAS C V5.xx, this is done automatically if you include
  230. "modplayer.h" in all your code modules which call modplayer. If you
  231. have a compiler which doesn't support argument passing in registers,
  232. then you have to write the stub routines in assembler.
  233.  
  234. That was it. See also the small example sources.
  235.  
  236. ==========================================================================
  237.